package com.finace.money.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.finace.money.R;
import com.finace.money.common.util.UIUtil;
import com.finace.money.interfaces.OnItemClickListener;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by S on 2018/2/28.
 */

public class MoneyInMoneyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private List<String> mDatas;
    private OnItemClickListener mListener;

    public void setmListener(OnItemClickListener mListener) {
        this.mListener = mListener;
    }

    public void setmDatas(List<String> mDatas) {
        this.mDatas = mDatas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MoneyInMoneyHolder(LayoutInflater.from(UIUtil.getContext()).inflate(R.layout.item_money_in, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MoneyInMoneyHolder moneyInMoneyHolder = (MoneyInMoneyHolder) holder;

        moneyInMoneyHolder.tvMoney.setText(mDatas.get(position));
        moneyInMoneyHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.onItemClick(view,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return (null != mDatas && mDatas.size() > 0) ? mDatas.size() : 0;
    }

    public class MoneyInMoneyHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_money)
        TextView tvMoney;
        public MoneyInMoneyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
